home *** CD-ROM | disk | FTP | other *** search
- Path: nntp1.best.com!usenet
- From: javaprog@best.com (John Lockwood)
- Newsgroups: comp.lang.c++
- Subject: Re: How to copy text to Win95 clipboard?
- Date: Sun, 14 Apr 1996 01:40:37 GMT
- Organization: Best Internet Communications
- Message-ID: <4kpl36$j8c@nntp1.best.com>
- References: <316ff634.6913883@news.demon.co.uk>
- NNTP-Posting-Host: javaprog.vip.best.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- martin@mckean.demon.co.uk (Martin McKean) wrote:
-
- >How do I set up a handle to a character string so that I can put that
- >string on the clipboard?
-
- >I'm using VC4++; grateful for any help!!
-
- Dude, here's a one-shot answer. But I really urge you to get a copy
- of Charles Petzold's Programming Windows and read it.
-
- #include <windows.h>
- #include <stdio.h>
- #include <assert.h>
-
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nShowCmd)
- {
- // Get a string and a length for the string:
- char * szTrySomething = "Thanks, John, for this free Windows lesson!"
- " I promise not to send you E-Mail.";
- DWORD dwBytes = strlen(szTrySomething) + 1;
-
- // Get a memory handle for the call
- HGLOBAL hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
- dwBytes);
- assert(hGlobal);
-
- // Turn the memory handle into a string:
-
- // Lock handle to get a pointer.
- char * szBuf = (char *) GlobalLock(hGlobal);
- assert(szBuf);
-
- // Copy the string into the pointer associated with the handle
- strcpy(szBuf, szTrySomething);
-
- // Unlock the pointer
- GlobalUnlock(hGlobal);
-
- // Do the deed!
- OpenClipboard(NULL);
- SetClipboardData(CF_TEXT, hGlobal);
- CloseClipboard();
-
- return 0;
- }
-
-
-
- Regards,
-
-
-
- John Lockwood
- john@wwg.com
- javaprog@best.com
- http://www.best.com/~javaprog
-
-